package com.eerl.pdev.terminal.cmd;

import com.eerl.pdev.util.Notice;
import com.eerl.pdev.util.ProjectFileUtil;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.jetbrains.annotations.NotNull;

public class TerminalActionMMake extends AnAction {

    public TerminalActionMMake() {
        super("Erl MMake", "", null);
    }

    @Override
    public void actionPerformed(@NotNull AnActionEvent e) {
        // xll_todo 提取成为配置项
        // xll_todo 提取优化
        // xll_todo 执行命令提取成配置项
        final String PROJECT_WSL_ABS_PATH = "/root/git/workspace/cahx_wspace/develop";

        // 获取当前项目
        Project project = e.getProject();
        if (project == null) return;

        // 获取当前打开的文件
        VirtualFile virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE);
        if (virtualFile == null) {
            Notice.popMessage(e, "No file is currently open");
            return;
        }

        Terminal instance = Terminal.getInstance(project);
        ProjectFileUtil.saveFile(e);
        String command = "cd " + PROJECT_WSL_ABS_PATH + ";mm ";
        instance.executeCommand(command);
    }
}
